package com.hhs.storage.controller;

import com.hhs.storage.bean.JxcRole;
import com.hhs.storage.bean.User;
import com.hhs.storage.config.redis.RedisUtil;
import com.hhs.storage.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

//所有页面的跳转都通过此类
@Controller
@Slf4j
public class WebPageController {
    @Resource
    RoleService roleService;


    @Resource
    RedisUtil redisUtil;
    //登录页
    @RequestMapping("login")
    public String login(){
        return "login";
    }
    //wy
    @RequestMapping("zbz")
    public String zbz(){
        return "zbz";
    }
    //主页
    @RequestMapping("go/index")
    public String index(){
        log.debug("跳转到主页");
        return "index";
    }
    @RequestMapping("go/type")
    @RequiresRoles("admin")
    public String type(){
        log.debug("跳转到类别管理");
        return "type";
    }
    @RequestMapping("go/menu")
    @RequiresRoles("admin")
    public String menu(){
        log.debug("跳转到菜单页");
        return "menu";
    }
    @RequestMapping("go/role")
    @RequiresRoles("admin")
    public String role(){
        log.debug("跳转到角色页");
        return "role";
    }
    @RequestMapping("go/user")
    @RequiresRoles("admin")
    public String user(){
        log.debug("跳转到用户管理页");
        return "user";
    }
    @RequestMapping("go/kf")
    @RequiresRoles("admin")
    public String kf(){
        log.debug("跳转到客服管理页");
        return "kf";
    }
    @RequestMapping("go/huiyuantc")
    @RequiresRoles(value={"agent","admin"},logical= Logical.OR)
    public String huiyuantc(){
        log.debug("跳转到会员套餐管理页");
        return "huiyuantc";
    }

    @RequestMapping("go/useryj")
    @RequiresRoles("admin")
    public String yhyj(){
        log.debug("跳转到用户意见管理页");
        return "useryj";
    }
    @RequestMapping("go/fl")
    @RequiresRoles("admin")
    public String fl(){
        log.debug("跳转到分类管理页");
        return "fl";
    }
    @RequestMapping("go/usercz")
    @RequiresRoles("admin")
    public String usercz(){
        log.debug("跳转到充值管理页");
        return "usercz";
    }

    @RequestMapping("go/cjsj")
    @RequiresRoles("admin")
    public String cjsj(){
        log.debug("跳转到采集数据管理页");
        return "cjsj";
    }

    @RequestMapping("go/xjry")
    @RequiresRoles(value={"agent","admin"},logical= Logical.OR)
    public String xjry(){
        log.debug("跳转到下级人员管理页");
        return "xjry";
    }
    @RequestMapping("go/ym")
    @RequiresRoles("admin")
    public String ym(){
        log.debug("跳转到域名管理页");
        return "ym";
    }

    @RequestMapping("go/gtname")
    public String gtname(){
        log.debug("跳转到名字管理页");
        return "gtname";
    }
    @RequestMapping("go/mpass")
    @RequiresRoles("admin")
    public String mpass(){
        log.debug("跳转到修改密码管理页");
        return "mpass";
    }
    @RequestMapping("go/kflt")
    @RequiresRoles("admin")
    public String kflt(){
        log.debug("跳转到修改密码管理页");
        return "kflt";
    }

    @RequestMapping("go/gcustomer")
    @RequiresRoles("admin")
    public String gcustomer(){
        log.debug("跳转到登录人员管理页");
        return "gcustomer";
    }

    @RequestMapping("go/product")
    public String product(Model model){
        log.debug("跳转到库存汇总页");
        //获取角色，用于前端按钮的显示
        User user = (User) SecurityUtils.getSubject().getSession().getAttribute("user");
        Map<String, Object> map = roleService.getByUserId(user.getId());
        List<JxcRole> list = ( List<JxcRole> )map.get("data");
        String roleStr=",";
        for (JxcRole jxcRole : list) {
            roleStr +=jxcRole.getFlag()+",";
        }
        model.addAttribute("roleStr", roleStr);
        return "product";
    }

    @RequestMapping("go/productReview")
    @RequiresRoles("admin")
    public String productReview(){
        log.debug("跳转到单据审核页");
        return "productOrderReview";
    }
    @RequestMapping("go/productOrderOn/{orderType}")
    public String productOrderOn(Model model,@PathVariable("orderType") String orderType){
        log.debug("跳转到出/入库单页");
        model.addAttribute("orderType", orderType);
        return "productOrderOn";
    }
}
